package crp.extensions.scy.sso;


import com.qwlabs.lang.S2;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public final class SCYResponseUtil {
    private SCYResponseUtil() {
    }

    public static String getAttribute(String response, String tag) {
        if (S2.isBlank(response)) {
            return null;
        }
        String startTag = String.format("<%s>", tag);
        String endTag = String.format("</%s>", tag);
        int startIndex = response.indexOf(startTag);
        int endIndex = response.lastIndexOf(endTag);
        if (startIndex <= 0 || endIndex <= 0) {
            LOGGER.warn("can not found tag '{}' in response '{}'", tag, response);
            return null;
        }
        return response.substring(startIndex + startTag.length(), endIndex).trim();
    }
}
